package re56.layer;

import java.util.ArrayList;
import java.util.List;

import re56.packet.PDCCHPacket;
import re56.packet.PDSCHPacket;
import re56.packet.PUCCHPacket;
import re56.packet.PUSCHPacket;
import re56.packet.Packet;

public class UEPhysicalLayer extends PhysicalLayer
{
	List<Integer> DLBlocks = new ArrayList<Integer>();
	List<Integer> ULBlocks = new ArrayList<Integer>();
	
	public UEPhysicalLayer(MACLayer Mac, RadioLayer radioLayerDL, RadioLayer radioLayerUL)
	{
		super(Mac, radioLayerDL, radioLayerUL);
	}
	
	
	@Override
	public void send(Packet p)
	{
		// let's write the packet into the UL Radio Layer.
		if(p instanceof PUCCHPacket)
		{
			radioLayerUL.writeInPUCCH((PUCCHPacket) p);
		}
		else if(p instanceof PUSCHPacket)
		{
			radioLayerUL.writeInPUSCH((PUSCHPacket) p);
		}
	}
	

	@Override
	public void receive()
	{
		// this function is called on each sub-frame. (should be 1ms)
		// as we're in the UE PhysicalLayer,
		// we have to read into the Downlink Radio Layer.
		
		// first check the PDSCH Channel
		// User Data
		PDCCHPacket pdcch = radioLayerDL.readInPDCCH();
		
		if(pdcch != null)
			Mac.receivePacket(pdcch);
		
		
		PDSCHPacket pdsch = radioLayerDL.readInPDSCH();
		
		if(pdsch != null)
			Mac.receivePacket(pdsch);
	}
}
